<?php

class mkathod{
	
	
	public function kategoriehodnotenia(){
		conndb::getInst()->query("SELECT DISTINCT k.id, k.Meno, k.Popis, p.Meno AS kat   FROM sutazne_kolo e INNER JOIN kategoria_hodnotenia d on (e.id=d.id_sutazne_kolo) 
		INNER JOIN typ_kategoria_hodnotenia k on (k.id=d.id_kategoria_hodnotenia) INNER JOIN sutazna_kategoria p on (p.id=e.id_sutazna_kategoria) WHERE e.id_sutaz=\"".$_SESSION['idupravsu']."\" ORDER BY p.Meno ");

		$kat = conndb::getInst()->getRowsAsArrayOfObjects();
		return $kat;
	}
	public function kategorie(){
		conndb::getInst()->query("SELECT DISTINCT p.id, p.Meno FROM sutazne_kolo e INNER JOIN sutazna_kategoria p on (e.id_sutazna_kategoria=p.id) WHERE e.id_sutaz=\"".$_SESSION['idupravsu']."\"  ");
		$kat = conndb::getInst()->getRowsAsArrayOfObjects();
		return $kat;
	}
	
	public function odstran($id){
		foreach ($id as $co){
			$pole=explode("|",$co);
			conndb::getInst()->query("SELECT e.id FROM sutazne_kolo e INNER JOIN sutazna_kategoria d on (d.id=e.id_sutazna_kategoria) WHERE e.id_sutaz=\"".$_SESSION['idupravsu']."\" AND d.Meno='".$pole[1]."' ");
			$kola = conndb::getInst()->getRowsAsArrayOfObjects();
			foreach($kola as $kol){
				conndb::getInst()->query("DELETE FROM kategoria_hodnotenia WHERE id_sutazne_kolo=\"".$kol->id."\" AND id_kategoria_hodnotenia='".$pole[0]."' ");
			}
				
		}
			
	}
	
	public function pridaj($meno, $idkat){
		conndb::getInst()->query("SELECT id FROM typ_kategoria_hodnotenia WHERE Meno=\"".mysql_real_escape_string($meno)."\"  ");
		$kathod = conndb::getInst()->getRowAsObject();
		if ($kathod=='' or empty($kathod)){}else{
			$katidhod= $kathod->id;
			conndb::getInst()->query("SELECT * FROM sutazne_kolo WHERE meno IS NOT NULL AND id_sutaz=\"".$_SESSION['idupravsu']."\"  AND id_sutazna_kategoria=\"".$idkat."\" ");
			$kola = conndb::getInst()->getRowsAsArrayOfObjects();
			if ($kola=='' or empty($kola)){ 
				conndb::getInst()->query("SELECT * FROM sutazne_kolo WHERE meno IS NULL AND id_sutaz=\"".$_SESSION['idupravsu']."\"  AND id_sutazna_kategoria=\"".$idkat."\" ");
				$kola = conndb::getInst()->getRowsAsArrayOfObjects();// sutaz s kolom
				
			}
			foreach($kola as $kol){
					conndb::getInst()->query("INSERT INTO kategoria_hodnotenia (id_kategoria_hodnotenia, id_sutazne_kolo) VALUES ('".$katidhod."', '".$kol->id."') ");
			}
		}
	}
	
}
?>

